package org.jsoup.nodes;

import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import o.gbe;
import o.gbg;
import o.gbi;
import o.gbj;
import o.gbk;
import o.gbm;
import o.gbn;
import o.gbp;
import o.gbq;
import o.gbs;
import o.gbx;
import o.gcj;
import o.gck.ak;
import o.gck.e;
import o.gcl;
import o.gcm;
import o.gcq;
import org.jsoup.nodes.Document.e.a;
import org.jsoup.select.Elements;
import org.jsoup.select.Selector;

public class Element extends gbq {
    private static final Pattern ˊ = Pattern.compile("\\s+");
    private static final List<gbq> ˎ = Collections.emptyList();
    private String ʻ;
    private gcj ʼ;
    private WeakReference<List<Element>> ʽ;
    List<gbq> ˏ;
    private gbi ᐝ;

    static final class b extends gbe<gbq> {
        private final Element ˏ;

        b(Element element, int i) {
            super(i);
            this.ˏ = element;
        }

        public void ˊ() {
            this.ˏ.ʼॱ();
        }
    }

    public /* synthetic */ Object clone() throws CloneNotSupportedException {
        return ʼ();
    }

    public /* synthetic */ gbq ʻ() {
        return ʼ();
    }

    public /* synthetic */ gbq ʽ(gbq o_gbq) {
        return ˋ(o_gbq);
    }

    public /* synthetic */ gbq ˋ(String str, String str2) {
        return ˏ(str, str2);
    }

    public /* synthetic */ gbq ˎˎ() {
        return ᐝॱ();
    }

    public /* synthetic */ gbq ˏ(gbq o_gbq) {
        return ॱ(o_gbq);
    }

    public Element(gcj o_gcj, String str, gbi o_gbi) {
        gbj.ˋ((Object) o_gcj);
        gbj.ˋ((Object) str);
        this.ˏ = ˎ;
        this.ʻ = str;
        this.ᐝ = o_gbi;
        this.ʼ = o_gcj;
    }

    public Element(gcj o_gcj, String str) {
        this(o_gcj, str, null);
    }

    public List<gbq> ॱˊ() {
        if (this.ˏ == ˎ) {
            this.ˏ = new b(this, 4);
        }
        return this.ˏ;
    }

    public boolean ˏॱ() {
        return this.ᐝ != null;
    }

    public gbi ͺ() {
        if (!ˏॱ()) {
            this.ᐝ = new gbi();
        }
        return this.ᐝ;
    }

    public String ˏ() {
        return this.ʻ;
    }

    public void ˋ(String str) {
        this.ʻ = str;
    }

    public int ॱ() {
        return this.ˏ.size();
    }

    public String ˎ() {
        return this.ʼ.ˏ();
    }

    public String ˊॱ() {
        return this.ʼ.ˏ();
    }

    public String ˋॱ() {
        return this.ʼ.ॱ();
    }

    public gcj ʻॱ() {
        return this.ʼ;
    }

    public boolean ॱˋ() {
        return this.ʼ.ˎ();
    }

    public String ॱᐝ() {
        return ͺ().ˏ("id");
    }

    public Element ˏ(String str, String str2) {
        super.ˋ(str, str2);
        return this;
    }

    public final Element ᐝॱ() {
        return (Element) this.ॱ;
    }

    public Element ˎ(int i) {
        return (Element) ˋ().get(i);
    }

    public Elements ॱˎ() {
        return new Elements(ˋ());
    }

    private List<Element> ˋ() {
        if (this.ʽ != null) {
            List<Element> list = (List) this.ʽ.get();
            if (list != null) {
                return list;
            }
        }
        int size = this.ˏ.size();
        List<Element> arrayList = new ArrayList(size);
        for (int i = 0; i < size; i++) {
            gbq o_gbq = (gbq) this.ˏ.get(i);
            if (o_gbq instanceof Element) {
                arrayList.add((Element) o_gbq);
            }
        }
        this.ʽ = new WeakReference(arrayList);
        return arrayList;
    }

    public void ʼॱ() {
        super.ʼॱ();
        this.ʽ = null;
    }

    public List<gbx> ʾ() {
        List arrayList = new ArrayList();
        for (gbq o_gbq : this.ˏ) {
            if (o_gbq instanceof gbx) {
                arrayList.add((gbx) o_gbq);
            }
        }
        return Collections.unmodifiableList(arrayList);
    }

    public Elements select(String str) {
        return Selector.ˎ(str, this);
    }

    public Element ˊ(gbq o_gbq) {
        gbj.ˋ((Object) o_gbq);
        ᐝ(o_gbq);
        ॱˊ();
        this.ˏ.add(o_gbq);
        o_gbq.ˊ(this.ˏ.size() - 1);
        return this;
    }

    public Element ˋ(gbq o_gbq) {
        return (Element) super.ʽ(o_gbq);
    }

    public Elements ʽॱ() {
        if (this.ॱ == null) {
            return new Elements(0);
        }
        List<Element> ˋ = ᐝॱ().ˋ();
        Elements elements = new Elements(ˋ.size() - 1);
        for (Element element : ˋ) {
            if (element != this) {
                elements.add(element);
            }
        }
        return elements;
    }

    public Element ˈ() {
        if (this.ॱ == null) {
            return null;
        }
        List ˋ = ᐝॱ().ˋ();
        Object valueOf = Integer.valueOf(ˎ(this, ˋ));
        gbj.ˋ(valueOf);
        if (valueOf.intValue() > 0) {
            return (Element) ˋ.get(valueOf.intValue() - 1);
        }
        return null;
    }

    public int ʿ() {
        if (ᐝॱ() == null) {
            return 0;
        }
        return ˎ(this, ᐝॱ().ˋ());
    }

    private static <E extends Element> int ˎ(Element element, List<E> list) {
        int size = list.size();
        for (int i = 0; i < size; i++) {
            if (list.get(i) == element) {
                return i;
            }
        }
        return 0;
    }

    public Elements ˊ(String str) {
        gbj.ॱ(str);
        return gcl.ˎ(new ak(gbg.ˋ(str)), this);
    }

    public Elements ˉ() {
        return gcl.ˎ(new e(), this);
    }

    public String ˊˋ() {
        final StringBuilder ˏ = gbk.ˏ();
        gcm.ˏ(new gcq(this) {
            final /* synthetic */ Element ॱ;

            public void ˏ(gbq o_gbq, int i) {
                if (o_gbq instanceof gbx) {
                    Element.ˋ(ˏ, (gbx) o_gbq);
                } else if (o_gbq instanceof Element) {
                    Element element = (Element) o_gbq;
                    if (ˏ.length() <= 0) {
                        return;
                    }
                    if ((element.ॱˋ() || element.ʼ.ˏ().equals("br")) && !gbx.ˊ(ˏ)) {
                        ˏ.append(' ');
                    }
                }
            }

            public void ˎ(gbq o_gbq, int i) {
                if ((o_gbq instanceof Element) && ((Element) o_gbq).ॱˋ() && (o_gbq.ͺॱ() instanceof gbx) && !gbx.ˊ(ˏ)) {
                    ˏ.append(' ');
                }
            }
        }, this);
        return gbk.ˎ(ˏ).trim();
    }

    public String ˊᐝ() {
        StringBuilder ˏ = gbk.ˏ();
        ˊ(ˏ);
        return gbk.ˎ(ˏ).trim();
    }

    private void ˊ(StringBuilder stringBuilder) {
        for (gbq o_gbq : this.ˏ) {
            if (o_gbq instanceof gbx) {
                ˋ(stringBuilder, (gbx) o_gbq);
            } else if (o_gbq instanceof Element) {
                ॱ((Element) o_gbq, stringBuilder);
            }
        }
    }

    private static void ˋ(StringBuilder stringBuilder, gbx o_gbx) {
        String ʼ = o_gbx.ʼ();
        if (ˎ(o_gbx.ॱ) || (o_gbx instanceof gbp)) {
            stringBuilder.append(ʼ);
        } else {
            gbk.ˋ(stringBuilder, ʼ, gbx.ˊ(stringBuilder));
        }
    }

    private static void ॱ(Element element, StringBuilder stringBuilder) {
        if (element.ʼ.ˏ().equals("br") && !gbx.ˊ(stringBuilder)) {
            stringBuilder.append(HwAccountConstants.BLANK);
        }
    }

    public static boolean ˎ(gbq o_gbq) {
        if (!(o_gbq instanceof Element)) {
            return false;
        }
        o_gbq = (Element) o_gbq;
        int i = 0;
        while (!o_gbq.ʼ.ʼ()) {
            o_gbq = o_gbq.ᐝॱ();
            i++;
            if (i >= 6) {
                return false;
            }
            if (o_gbq == null) {
                return false;
            }
        }
        return true;
    }

    public String ˋˊ() {
        StringBuilder ˏ = gbk.ˏ();
        for (gbq o_gbq : this.ˏ) {
            if (o_gbq instanceof gbm) {
                ˏ.append(((gbm) o_gbq).ˊ());
            } else if (o_gbq instanceof gbn) {
                ˏ.append(((gbn) o_gbq).ˊ());
            } else if (o_gbq instanceof Element) {
                ˏ.append(((Element) o_gbq).ˋˊ());
            } else if (o_gbq instanceof gbp) {
                ˏ.append(((gbp) o_gbq).ʼ());
            }
        }
        return gbk.ˎ(ˏ);
    }

    public boolean ॱ(String str) {
        String ˏ = ͺ().ˏ("class");
        int length = ˏ.length();
        int length2 = str.length();
        if (length == 0 || length < length2) {
            return false;
        }
        if (length == length2) {
            return str.equalsIgnoreCase(ˏ);
        }
        int i = 0;
        boolean z = false;
        for (int i2 = 0; i2 < length; i2++) {
            if (Character.isWhitespace(ˏ.charAt(i2))) {
                if (!z) {
                    continue;
                } else if (i2 - i == length2 && ˏ.regionMatches(true, i, str, 0, length2)) {
                    return true;
                } else {
                    z = false;
                }
            } else if (!z) {
                i = i2;
                z = true;
            }
        }
        if (z && length - i == length2) {
            return ˏ.regionMatches(true, i, str, 0, length2);
        }
        return false;
    }

    public void ˋ(Appendable appendable, int i, Document.e eVar) throws IOException {
        if (eVar.ॱ() && (this.ʼ.ˋ() || ((ᐝॱ() != null && ᐝॱ().ʻॱ().ˋ()) || eVar.ʻ()))) {
            if (!(appendable instanceof StringBuilder)) {
                ˎ(appendable, i, eVar);
            } else if (((StringBuilder) appendable).length() > 0) {
                ˎ(appendable, i, eVar);
            }
        }
        appendable.append('<').append(ˊॱ());
        if (this.ᐝ != null) {
            this.ᐝ.ˏ(appendable, eVar);
        }
        if (!this.ˏ.isEmpty() || !this.ʼ.ॱॱ()) {
            appendable.append('>');
        } else if (eVar.ˎ() == a.html && this.ʼ.ˊ()) {
            appendable.append('>');
        } else {
            appendable.append(" />");
        }
    }

    public void ˊ(Appendable appendable, int i, Document.e eVar) throws IOException {
        if (!this.ˏ.isEmpty() || !this.ʼ.ॱॱ()) {
            if (eVar.ॱ() && !this.ˏ.isEmpty() && (this.ʼ.ˋ() || (eVar.ʻ() && (this.ˏ.size() > 1 || (this.ˏ.size() == 1 && !(this.ˏ.get(0) instanceof gbx)))))) {
                ˎ(appendable, i, eVar);
            }
            appendable.append("</").append(ˊॱ()).append('>');
        }
    }

    public String ˊˊ() {
        StringBuilder ˏ = gbk.ˏ();
        ˋ((Appendable) ˏ);
        String ˎ = gbk.ˎ(ˏ);
        return gbs.ˏ(this).ॱ() ? ˎ.trim() : ˎ;
    }

    public <T extends Appendable> T ˋ(T t) {
        int size = this.ˏ.size();
        for (int i = 0; i < size; i++) {
            ((gbq) this.ˏ.get(i)).ॱ((Appendable) t);
        }
        return t;
    }

    public Element ʼ() {
        return (Element) super.ʻ();
    }

    protected Element ॱ(gbq o_gbq) {
        Element element = (Element) super.ˏ(o_gbq);
        element.ᐝ = this.ᐝ != null ? this.ᐝ.ˏ() : null;
        element.ʻ = this.ʻ;
        element.ˏ = new b(element, this.ˏ.size());
        element.ˏ.addAll(this.ˏ);
        return element;
    }
}
